package cn.edu.scau.cmi.yangzhengkai.multipleton;

import java.util.ArrayList;

/**
 * @author Administrator
 *
 */
public class Marshal {
	private static final int N = 10;
	private String name;

	private static ArrayList<Marshal> list = new ArrayList<>(N);

	private Marshal(String name) {
		this.name = name;
	}

	public static Marshal getMarshal(String name) {
		boolean isrepeated = false;
		int t = 0;
		if (list.size() < N) {
			for (int i = 0; i < list.size(); i++) {
				if (list.get(i).getName().equals(name)) {
					isrepeated = true;
					t = i;
					break;

				}
			}
			if (!isrepeated) {
				Marshal marshal = new Marshal(name);
				list.add(marshal);
				return marshal;
			} else
				return list.get(t);

		}

		else
			return null;

	}

	public String getName() {
		return name;
	}

}
